/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.fzhucc.modules.hot.controller;

import com.fzhucc.annotation.Log;
import com.fzhucc.annotation.rest.AnonymousGetMapping;
import com.fzhucc.annotation.rest.AnonymousPostMapping;
import com.fzhucc.modules.hot.domain.dto.HotRecordScaleCriteria;
import com.fzhucc.modules.hot.service.HotRecordService;
import com.fzhucc.modules.hot.domain.dto.HotRecordQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * @author yyg
 * @date 2024-01-29
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "首页:计数记录管理")
@RequestMapping("/api/hotRecord")
public class HotRecordController {

    private final HotRecordService hotRecordService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('hotRecord:list')")
    public void exportHotRecord(HttpServletResponse response, HotRecordQueryCriteria criteria) throws IOException {
        hotRecordService.download(hotRecordService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询首页计数记录")
    @ApiOperation("查询首页计数记录")
    @PreAuthorize("@el.check('hotRecord:list')")
    public ResponseEntity<Object> queryHotRecord(HotRecordQueryCriteria criteria, Pageable pageable) {
        return new ResponseEntity<>(hotRecordService.queryAll(criteria, pageable), HttpStatus.OK);
    }

    /*@Log("导出数据By时间")
    @ApiOperation("导出数据By时间")
    @GetMapping(value = "/downloadByTime")
    @PreAuthorize("@el.check('hotRecord:list')")
    public void exportHotRecord(HttpServletResponse response, HotRecordQueryCriteria2 criteria) throws IOException {
        hotRecordService.download(hotRecordService.queryAll2(criteria), response);
    }*/

    /*@PostMapping
    @Log("新增首页计数记录")
    @ApiOperation("新增首页计数记录")
    @PreAuthorize("@el.check('hotRecord:add')")
    public ResponseEntity<Object> createHotRecord(@Validated @RequestBody HotRecord resources){
        return new ResponseEntity<>(hotRecordService.create(resources), HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改首页计数记录")
    @ApiOperation("修改首页计数记录")
    @PreAuthorize("@el.check('hotRecord:edit')")
    public ResponseEntity<Object> updateHotRecord(@Validated @RequestBody HotRecord resources){
        hotRecordService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除首页计数记录")
    @ApiOperation("删除首页计数记录")
    @PreAuthorize("@el.check('hotRecord:del')")
    public ResponseEntity<Object> deleteHotRecord(@RequestBody Integer[] ids) {
        hotRecordService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }*/

    @AnonymousGetMapping(value = "/scaleData")
    @Log("根据时间点导入浏览数据")
    @ApiOperation("根据时间点导入浏览数据")
    public ResponseEntity<Object> scaleData(HotRecordScaleCriteria dto) {
        hotRecordService.scaleData(dto);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}